import request from '@/utils/request'
import type { DistributionScheme, SchemeListParams, SchemeListResponse, SchemeCreateData, SchemeUpdateData } from '@/types/api'

// 获取分发方案列表
export const getSchemeList = (params: SchemeListParams): Promise<SchemeListResponse> => {
  return request({
    url: '/distribution/scheme/list',
    method: 'get',
    params
  })
}

// 创建分发方案
export const createScheme = (data: SchemeCreateData): Promise<any> => {
  return request({
    url: '/distribution/scheme',
    method: 'post',
    data
  })
}

// 更新分发方案
export const updateScheme = (id: number, data: SchemeUpdateData): Promise<any> => {
  return request({
    url: `/distribution/scheme/${id}`,
    method: 'put',
    data
  })
}

// 删除分发方案
export const deleteScheme = (id: number): Promise<any> => {
  return request({
    url: `/distribution/scheme/${id}`,
    method: 'delete'
  })
}

// 更新分发方案状态
export const updateSchemeStatus = (id: number, status: number): Promise<any> => {
  return request({
    url: `/distribution/scheme/${id}/status`,
    method: 'put',
    params: { status }
  })
}

// 获取分发规则列表
export const getDistributionRules = (schemeId: number): Promise<any> => {
  return request({
    url: `/distribution/scheme/${schemeId}/rules`,
    method: 'get'
  })
}

// 创建分发规则
export const createDistributionRule = (schemeId: number, data: any): Promise<any> => {
  return request({
    url: `/distribution/scheme/${schemeId}/rules`,
    method: 'post',
    data
  })
}

// 更新分发规则
export const updateDistributionRule = (ruleId: number, data: any): Promise<any> => {
  return request({
    url: `/distribution/rule/${ruleId}`,
    method: 'put',
    data
  })
}

// 删除分发规则
export const deleteDistributionRule = (ruleId: number): Promise<any> => {
  return request({
    url: `/distribution/rule/${ruleId}`,
    method: 'delete'
  })
}